package linksinglelist;

public class Test {
    /**
     * 创造相交链表为了测试函数
     * @param headA
     * @param headB
     */
    public static void createCut(MySingleList.ListNode headA, MySingleList.ListNode headB){
        headB.next.next=headA.next.next;
    }

    public static void main(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(23);
        mySingleList1.addLast(34);
        mySingleList1.addLast(45);
        mySingleList1.addLast(56);
        mySingleList1.display();
        System.out.println("============================");
       // mySingleList1.createLoop();

        //boolean flag=mySingleList1.hasCycle();
        //System.out.println(flag);
        mySingleList1.display3(mySingleList1.head);
        System.out.println("============================");
        mySingleList1.display4(mySingleList1.head);

    }
    public static void main6(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(23);
        mySingleList1.addLast(34);
        mySingleList1.addLast(45);
        mySingleList1.addLast(56);
        mySingleList1.display();
        System.out.println("============================");
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(121);
        mySingleList2.addLast(122);
        mySingleList2.addLast(123);
        mySingleList2.addLast(124);
        mySingleList2.addLast(125);
        mySingleList2.display();
        System.out.println("============================");
        createCut(mySingleList1.head,mySingleList2.head);
        MySingleList.ListNode ret = mySingleList1.getIntersectionNode(mySingleList1.head,
                mySingleList2.head);
        System.out.println("相交的点："+ret.val);




    }
    public static void main5(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(23);
        mySingleList1.addLast(34);
        mySingleList1.addLast(45);
        mySingleList1.addLast(56);
        mySingleList1.display();
        System.out.println("============================");
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(1);
        mySingleList2.addLast(22);
        mySingleList2.addLast(57);
        mySingleList2.display();
        System.out.println("============================");
        MySingleList.ListNode ret = mySingleList1.mergeTwoLists(mySingleList1.head, mySingleList2.head);
        mySingleList1.display(ret);
        System.out.println("============================");
    }
    public static void main4(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addLast(12);
        mySingleList.addLast(23);
      //  mySingleList.addLast(34);
        mySingleList.addLast(45);
        mySingleList.addLast(56);
        mySingleList.display();
        System.out.println("============================");
        MySingleList.ListNode ret = mySingleList.middleNode();
        System.out.println(ret.val);
        mySingleList.reverseList();
        mySingleList.display();
        System.out.println("============================");
        try {
            MySingleList.ListNode ret1 = mySingleList.FindKthToTail(3);
            System.out.println(ret1.val);
        }catch (NullPointerException e){
            System.out.println("ret的值为null");
            e.printStackTrace();

        }

    }
    public static void main3(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addFirst(12);
        mySingleList.addFirst(13);
        mySingleList.addFirst(12);
        mySingleList.addFirst(17);
        mySingleList.addFirst(12);
        mySingleList.display();
        System.out.println("============================");
        mySingleList.removeAllKey(12);
        mySingleList.display();
        System.out.println("============================");
        mySingleList.clear();
        mySingleList.display();
        System.out.println("============================");



    }
    public static void main2(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addFirst(12);
        mySingleList.addFirst(23);
        mySingleList.addFirst(34);
        mySingleList.addFirst(45);
        mySingleList.addFirst(56);
        mySingleList.display();
        System.out.println("============================");
        mySingleList.addLast(997);
        mySingleList.addLast(998);
        mySingleList.addLast(999);
        mySingleList.display();
        System.out.println("============================");
        mySingleList.addIndex(0,888);
        mySingleList.display();
        mySingleList.addIndex(9,887);
        mySingleList.display();
        mySingleList.addIndex(3,886);
        mySingleList.display();
//        try {
//            mySingleList.addIndex(-1, 8888);
//        }catch (MySingleListIndexOutOfException e){
//            e.printStackTrace();
//        }
//        mySingleList.display();
        System.out.println("============================");
        mySingleList.remove(997);
        mySingleList.display();
        mySingleList.remove(888);
        mySingleList.display();
        mySingleList.remove(887);
        mySingleList.display();
        mySingleList.remove(-1);
        mySingleList.display();
    }
    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.createList();
        System.out.println("============================");
        boolean ret = mySingleList.contains(561);
        if(ret){
            System.out.println("存在这个节点的！");
        }else {
            System.out.println("不存在这个节点的！");
        }
        System.out.println("============================");
        int len = mySingleList.size();
        System.out.println(len);
        System.out.println("============================");


    }
}
